#pragma once
#include <MsHTML.h>
#include <vector>
#include "DOMNode.h"
// used to divide a DOM tree into visual blocks
class DOMNode;

class ElementPool
{
public:
	typedef std::vector<DOMNode*>::iterator iterator;
	inline iterator begin(){
		return m_pool.begin();
	}
	inline iterator end(){
		return m_pool.end();
	}
	inline void push_back(DOMNode* pElem){
		m_pool.push_back(pElem);
	}
	inline void clear(){
		m_pool.clear();
	}
private:
	std::vector<DOMNode* > m_pool;
};


class DOMTreeDivider
{
	friend class DOMNode;
public:
	DOMTreeDivider(void);
	~DOMTreeDivider(void);
	inline ElementPool* GetELementPool(){
		return &m_ElmentPool;
	}
	bool Update(IHTMLDocument2* pDoc);
	void DivideDomTree();
	void _DivideDomTree(DOMNode* pNode); //helper
	void BuildTree();
private:

	CComPtr<IHTMLDocument2> m_spDoc2;
	ElementPool m_ElmentPool;
	DOMNode *m_pDOMNodeRoot;
};
